<?php
namespace app\index\controller;

use app\facade\Auth;
use think\Db;

class Login extends Base
{
    public function doLogin()
    {
        $data = $this->request->post();
        $validate = new \app\validate\Login;
        if (!$validate->check($data)) {
            return $this->sendFail($validate->getError());
        }
        $user =Db::table("tb_card_shop")->where('username', $data['username'])->find();
        if (empty($user)) {
            return $this->sendFail('账号错误');
        }
        if ($user["pass"] != md5($data['password'])) {
            return $this->sendFail('密码错误');
        }
        return $this->sendSuccess('登陆成功', ['token' => Auth::set($user["id"]),"user"=>$user]);
    }
}
